#pragma once
#include <string>
#include "jmsg.h"
#include "client_connection.h"
class BaseGameImpl;
class BaseDesk;
class BaseRoom;
class ClientConnection;
struct BaseMsgPlayerInfo;
struct MessageHeader;

class BasePlayer
{
public:
	BasePlayer(void);
	~BasePlayer(void);

public:
	template<class T>
	void sendMessage(int cmdLayer, T& msg) {
		JMsgWriter writer;
		msg.encode(m_proto, &writer);
		m_connection->SendData(cmdLayer, 0, writer.getBuffer(), writer.getBufferLen());
	}

	void sendData(int mainCmd, int subCmd, void* data, int len);
	void sendRoomData(void* data, int len);
	void sendDeskData(void* data, int len);
private:
	friend BaseGameImpl;
	friend BaseRoom;
	friend BaseDesk;
	void getPlayerInfoMsg(BaseMsgPlayerInfo* info);

private:
	std::string m_userName;
	ClientConnection* m_connection;
	BaseDesk* m_desk;
	BaseRoom* m_room;
	JMsgProto* m_proto;
	int m_chairId;
	bool m_isLogin;
	bool m_isGuest;
	std::string m_nickName;
	std::string m_lastLoginTime;
	int m_score;
};
